package cz.muni.fi.pa165.library.web_layer;

import cz.muni.fi.pa165.library.web_layer.adminPages.Book.EditBook;
import cz.muni.fi.pa165.library.web_layer.adminPages.Book.ShowAllBook;
import cz.muni.fi.pa165.library.web_layer.adminPages.Borrow.AddBorrow;
import cz.muni.fi.pa165.library.web_layer.adminPages.Borrow.EditBorrow;
import cz.muni.fi.pa165.library.web_layer.adminPages.Borrow.ShowAllBorrow;
import cz.muni.fi.pa165.library.web_layer.adminPages.Reader.EditReader;
import cz.muni.fi.pa165.library.web_layer.adminPages.Reader.ShowAllReader;
import cz.muni.fi.pa165.library.web_layer.adminPages.RegistrationLibrarianForm;
import cz.muni.fi.pa165.library.web_layer.adminPages.reservation.EditReservation;
import cz.muni.fi.pa165.library.web_layer.adminPages.reservation.ShowAllReservation;
import cz.muni.fi.pa165.library.web_layer.readerPages.BookReservation;
import cz.muni.fi.pa165.library.web_layer.readerPages.ShowAllBookReader;
import org.apache.wicket.Session;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.request.Request;
import org.apache.wicket.request.Response;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Application object for your web application. If you want to run this application without deploying, run the Start class.
 *
 * @see com.mycompany.wicketexample3.Start#main(String[])
 */
public class WicketApplication extends WebApplication //AuthenticatedWebApplication
{      
   
        /**
         * @see org.apache.wicket.Application#getHomePage()
         */
        @Override
        public Class<? extends WebPage> getHomePage()
        {
            return HomePage.class;
        }

        /**
         * @see org.apache.wicket.Application#init()
         */
        @Override
        public void init()
        {
                super.init();
               
                // access to beans is provided by ApplicationContextProvider.getApplicationContext().getBean("beanName");
                ApplicationContextProvider ctxProvider = new ApplicationContextProvider();
                ctxProvider.setApplicationContext(new ClassPathXmlApplicationContext(
                        "classpath:META-INF/applicationContext.xml"));
               
                // add your configuration here        
                mountPage("/books/all", ShowAllBook.class);
                mountPage("/borrows/all", ShowAllBorrow.class);
                mountPage("/readers/all", ShowAllReader.class);
                mountPage("/reservations/all", ShowAllReservation.class);
                
                mountPage("/books/edit", EditBook.class);
                mountPage("/borrows/edit", EditBorrow.class);
                mountPage("/readers/edit", EditReader.class);
                mountPage("/reservations/create", EditReservation.class);
                
                mountPage("/borrows/add", AddBorrow.class);
                mountPage("/pa165", HomePage.class);
                mountPage("/login", Login.class);
                 mountPage("/logout", Logout.class);
                mountPage("/registration", RegistrationLibrarianForm.class);
                mountPage("/book/all", ShowAllBookReader.class);
                mountPage("/reservation/create", BookReservation.class);
        }
    
    @Override
    public Session newSession(Request request, Response response) {
       return new AuthenticatedSession(request);
    }
}
